Skip to content

refactor: order validation checks by parameter position in stats/base/dists/cauchy/*#11942

Merged
kgryte merged 14 commits intodevelopfrom
philipp/drift-stats-base-dists-cauchy-2026-05-05
May 5, 2026
Merged

refactor: order validation checks by parameter position in stats/base/dists/cauchy/*#11942
kgryte merged 14 commits intodevelopfrom
philipp/drift-stats-base-dists-cauchy-2026-05-05

Conversation

@Planeshifter
Copy link
Copy Markdown
Member

@Planeshifter Planeshifter commented May 5, 2026

Aligning validation prologues across stats/base/dists/cauchy/* to follow parameter declaration order, per @Planeshifter's review feedback on this PR. Originally surfaced by a cross-package API drift sweep over the namespace; the routine identified quantile as the lone outlier under a majority-vote model, but parameter-order is the correct convention and applies in the opposite direction (everything but ctor needs the swap).

Description

Eight commits, one per outlier package, each a 1-line guard reorder. Behavior is unchanged in every case — every branch in the disjunction returns NaN, so swapping the order of the operands does not affect any observable result.

Package Signature Before (NaN guards) After (NaN guards)
cdf (x, x0, gamma) x, gamma, x0 x, x0, gamma
logcdf (x, x0, gamma) x, gamma, x0 x, x0, gamma
logpdf (x, x0, gamma) x, gamma, x0 x, x0, gamma
pdf (x, x0, gamma) x, gamma, x0 x, x0, gamma
entropy (x0, gamma) gamma, x0 x0, gamma
median (x0, gamma) gamma, x0 x0, gamma
mode (x0, gamma) gamma, x0 x0, gamma
quantile (p, x0, gamma) gamma, x0, …, p p, x0, gamma, …

ctor is untouched — it's a class constructor that throws TypeError via format rather than returning NaN, and its existing checks already follow (x0, gamma) order.

Related Issues

None.

Questions

None.

Other

Validation

  • Reorders are within the operands of a single boolean disjunction whose every branch returns NaN; observable behavior is unchanged.
  • The quantile test suite (test/test.js, test/test.factory.js, test/test.native.js) only asserts isnan(result) === true on invalid inputs and never inspects which check fired. Same is true for the other seven test suites — they exercise NaN inputs but assert only on the result, not on ordering.
  • Cross-reference: ctor/lib/main.js validates x0/gamma itself before forwarding to the numeric siblings, so it is unaffected by the internal prologue order in those siblings.

Out of scope

  • lib/factory.js files in cdf, logcdf, logpdf, pdf, quantile show the same parameter-order convention drift (and quantile/lib/factory.js additionally uses gamma <= 0 instead of gamma <= 0.0). Logged as a follow-up — happy to fold them into this PR if preferred.

Checklist

AI Assistance

  • Yes
  • No

If you answered "yes" above, how did you use AI assistance?

  • Code generation (e.g., when writing an implementation or fixing a bug)
  • Test/benchmark generation
  • Documentation (including examples)
  • Research and understanding

Disclosure

This PR was authored by Claude Code. The initial commit (a709d01) was produced by an automated cross-package API drift sweep over the stats/base/dists/cauchy namespace using a 75% majority-vote model. After @Planeshifter's review feedback that validation order should follow parameter declaration order, eight follow-up commits were authored mechanically to apply that convention across the seven sibling packages and to redirect the quantile reorder accordingly.


@stdlib-js/reviewers

…h namespace majority

Reorder NaN guards in the public quantile so that `isnan( gamma )` precedes
`isnan( x0 )`, matching the contiguous validation pattern present in 7 of the
9 sibling packages in `@stdlib/stats/base/dists/cauchy/*` (78% conformance).
Behavior is unchanged: any matching branch returns `NaN`.
@stdlib-bot stdlib-bot added the Statistics Issue or pull request related to statistical functionality. label May 5, 2026
@stdlib-bot
Copy link
Copy Markdown
Contributor

stdlib-bot commented May 5, 2026

Coverage Report

Package Statements Branches Functions Lines
stats/base/dists/cauchy/cdf $\color{green}287/287$
$\color{green}+100.00%$
$\color{green}19/19$
$\color{green}+100.00%$
$\color{green}4/4$
$\color{green}+100.00%$
$\color{green}287/287$
$\color{green}+100.00%$
stats/base/dists/cauchy/entropy $\color{green}161/161$
$\color{green}+100.00%$
$\color{green}9/9$
$\color{green}+100.00%$
$\color{green}2/2$
$\color{green}+100.00%$
$\color{green}161/161$
$\color{green}+100.00%$
stats/base/dists/cauchy/logcdf $\color{green}289/289$
$\color{green}+100.00%$
$\color{green}19/19$
$\color{green}+100.00%$
$\color{green}4/4$
$\color{green}+100.00%$
$\color{green}289/289$
$\color{green}+100.00%$
stats/base/dists/cauchy/logpdf $\color{green}293/293$
$\color{green}+100.00%$
$\color{green}19/19$
$\color{green}+100.00%$
$\color{green}4/4$
$\color{green}+100.00%$
$\color{green}293/293$
$\color{green}+100.00%$
stats/base/dists/cauchy/median $\color{green}159/159$
$\color{green}+100.00%$
$\color{green}9/9$
$\color{green}+100.00%$
$\color{green}2/2$
$\color{green}+100.00%$
$\color{green}159/159$
$\color{green}+100.00%$
stats/base/dists/cauchy/mode $\color{green}159/159$
$\color{green}+100.00%$
$\color{green}9/9$
$\color{green}+100.00%$
$\color{green}2/2$
$\color{green}+100.00%$
$\color{green}159/159$
$\color{green}+100.00%$
stats/base/dists/cauchy/pdf $\color{green}293/293$
$\color{green}+100.00%$
$\color{green}19/19$
$\color{green}+100.00%$
$\color{green}4/4$
$\color{green}+100.00%$
$\color{green}293/293$
$\color{green}+100.00%$
stats/base/dists/cauchy/quantile $\color{green}306/306$
$\color{green}+0.00%$
$\color{green}23/23$
$\color{green}+0.00%$
$\color{green}4/4$
$\color{green}+0.00%$
$\color{green}306/306$
$\color{green}+0.00%$

The above coverage report was generated for the changes in this PR.

Copy link
Copy Markdown
Member Author

@Planeshifter Planeshifter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should instead change all the other packages since the order of the checks should follow the parameter order.

claude added 8 commits May 5, 2026 14:33
…ts/cauchy/cdf`

Reorder NaN guards so checks follow declaration order `(x, x0, gamma)`.
Behavior unchanged: any matching branch returns `NaN`.
…ts/cauchy/logcdf`

Reorder NaN guards so checks follow declaration order `(x, x0, gamma)`.
Behavior unchanged: any matching branch returns `NaN`.
…ts/cauchy/logpdf`

Reorder NaN guards so checks follow declaration order `(x, x0, gamma)`.
Behavior unchanged: any matching branch returns `NaN`.
…ts/cauchy/pdf`

Reorder NaN guards so checks follow declaration order `(x, x0, gamma)`.
Behavior unchanged: any matching branch returns `NaN`.
…ts/cauchy/entropy`

Reorder NaN guards so checks follow declaration order `(x0, gamma)`.
Behavior unchanged: any matching branch returns `NaN`.
…ts/cauchy/median`

Reorder NaN guards so checks follow declaration order `(x0, gamma)`.
Behavior unchanged: any matching branch returns `NaN`.
…ts/cauchy/mode`

Reorder NaN guards so checks follow declaration order `(x0, gamma)`.
Behavior unchanged: any matching branch returns `NaN`.
…ts/cauchy/quantile`

Move `isnan( p )` to the front so the validation prologue follows declaration
order `(p, x0, gamma)`. Supersedes the prior majority-vote ordering on this
branch. Behavior unchanged: any matching branch returns `NaN`.
@Planeshifter Planeshifter changed the title fix: align stats/base/dists/cauchy/quantile validation prologue with namespace majority fix: order validation checks by parameter position in stats/base/dists/cauchy/* May 5, 2026
Copy link
Copy Markdown
Member Author

Done — pushed eight follow-up commits, one per package, reordering the NaN guards to match parameter declaration order in cdf, logcdf, logpdf, pdf, entropy, median, mode, and quantile. ctor is untouched (it already follows (x0, gamma) order and uses a different exception-based validation path).

Updated the PR title and body to reflect the new direction.

Note: lib/factory.js in cdf/logcdf/logpdf/pdf/quantile shows the same drift; left out of scope for now but can fold into this PR if you'd prefer to keep it together.


Generated by Claude Code

@Planeshifter
Copy link
Copy Markdown
Member Author

Note: lib/factory.js in cdf/logcdf/logpdf/pdf/quantile shows the same drift; left out of scope for now but can fold into this PR if you'd prefer to keep it together.

Let's address this too.

claude added 5 commits May 5, 2026 14:37
…ts/cauchy/cdf/lib/factory.js`

Reorder NaN guards in the factory so checks follow declaration order
`(x0, gamma)`. Behavior unchanged: any matching branch returns
`constantFunction( NaN )`.
…ts/cauchy/logcdf/lib/factory.js`

Reorder NaN guards in the factory so checks follow declaration order
`(x0, gamma)`. Behavior unchanged: any matching branch returns
`constantFunction( NaN )`.
…ts/cauchy/logpdf/lib/factory.js`

Reorder NaN guards in the factory so checks follow declaration order
`(x0, gamma)`. Behavior unchanged: any matching branch returns
`constantFunction( NaN )`.
…ts/cauchy/pdf/lib/factory.js`

Reorder NaN guards in the factory so checks follow declaration order
`(x0, gamma)`. Behavior unchanged: any matching branch returns
`constantFunction( NaN )`.
…se/dists/cauchy/quantile/lib/factory.js`

Match the float-literal style used by the four sibling factories
(cdf, logcdf, logpdf, pdf). Behavior unchanged.
Copy link
Copy Markdown
Member Author

Folded the lib/factory.js reorders into this PR — five additional commits:

  • cdf, logcdf, logpdf, pdf: swap NaN guards so the order matches factory(x0, gamma).
  • quantile: factory order was already correct; only normalized the scale-parameter guard from gamma <= 0 to gamma <= 0.0 to match the four siblings' float-literal style.

Behavior is unchanged in all five files.


Generated by Claude Code

@Planeshifter Planeshifter changed the title fix: order validation checks by parameter position in stats/base/dists/cauchy/* refactor: order validation checks by parameter position in stats/base/dists/cauchy/* May 5, 2026
@Planeshifter Planeshifter marked this pull request as ready for review May 5, 2026 14:38
@Planeshifter Planeshifter requested review from a team and kgryte May 5, 2026 14:38
@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label May 5, 2026
@kgryte kgryte removed the Needs Review A pull request which needs code review. label May 5, 2026
@kgryte kgryte merged commit 0a5fc6c into develop May 5, 2026
37 checks passed
@kgryte kgryte deleted the philipp/drift-stats-base-dists-cauchy-2026-05-05 branch May 5, 2026 22:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Statistics Issue or pull request related to statistical functionality.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants